package com.ecity.util {
	import com.ecity.events.GameEvent;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.utils.clearTimeout;
	import flash.utils.setTimeout;
	
	/**
	 * ...
	 * @author yicheng.zhang
	 */
	public class GridEngine extends Sprite {
		public static const b4p0:Array = [[16,23,24,27],[28, 34, 24, 27]];
		public static const b4p1:Array = [[35,39,20,27],[35, 39, 9, 15]];
		public static const b4p3:Array = [[10,13,10,17],[10,13,21,28]];
		public static const b4p2:Array = [[26, 33, 10, 13], [15, 21, 10, 13]];
		
		public static const handleft1:Array = [];
	
		private var cornerMap:HashMap = new HashMap();
		
		public function start():void {
			//if(
		}
		
		public function judge(mx:int,my:int):void {
			if (mx < 7 && my < 7) {
				savehandle(1);
			}
			if (mx <7 && my >31) {
				savehandle(2);
			}
			if (mx >43 && my < 7) {
				savehandle(3);
			}
			if (mx >43&& my >31) {
				savehandle(4);
			}
			trace(">>>>>>>>>---------mx:",mx," , my:",my,"----------->");
		}
		
		private function savehandle(corner:int):void {
			cornerMap.put(corner.toString(),corner);
			var st:uint = setTimeout(clearSession, 5000, corner, st);
			trace(">>>>>>>>>---------",cornerMap.size(),"----------->");
			if (cornerMap.size() == 4) {
				this.dispatchEvent(new GameEvent(GameEvent.REQ_GAME_START));
			}
		}
		
		public function hitTestZone(mx:int, my:int, areas:Array):int {
			if (mx > areas[0][0] && mx < areas[0][1] && my > areas[0][2] && my < areas[0][3]) {
				return 1;
			}
			if (mx > areas[1][0] && mx < areas[1][1] && my > areas[1][2] && my < areas[1][3]) {
				return -1;
			}
			return 0;
			
		}
		
		private function clearSession():void {
			cornerMap.remove(arguments[0].toString());
			clearTimeout(arguments[1]);
		}
		
	}

}